package projcet.test.student.student;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class QueryAdapter extends BaseAdapter {

    List<StudentInfo> studentInfoList;
    private Context mContext;
    private LayoutInflater mInflater;
    private List<Info> mInfo;

    public QueryAdapter(List<StudentInfo> studentInfoList, Context mContext, LayoutInflater mInflater, List<Info> mInfo) {
        this.studentInfoList = studentInfoList;
        this.mContext = mContext;
        this.mInflater = mInflater;
        this.mInfo = mInfo;
    }

    @Override
    public int getCount() {
        return studentInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return studentInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View viewStudent = mInflater.inflate(R.layout.item_query,null);
        StudentInfo student = studentInfoList.get(position);

        final TextView tvSubjcet = (TextView)viewStudent.findViewById(R.id.tv_item_subject);
        final TextView tvTeacher = (TextView)viewStudent.findViewById(R.id.tv_item_teacher);
        final TextView tvScore = (TextView)viewStudent.findViewById(R.id.tv_item_score);
        tvScore.setText(student.getTotal()+"");
        String  subject="";
        String  teacher="";
        for (int i = 0; i < mInfo.size(); i++) {
            if(student.getSubject().equals(mInfo.get(i).getSubject())){
                subject=mInfo.get(i).getSubject();
                teacher=mInfo.get(i).getTeacher();
                break;
            }
        }
        tvTeacher.setText(teacher);
        tvSubjcet.setText(subject);

        return viewStudent;
    }





}
